import { createStore } from 'vuex';
import user from './modules/user';

// 创建一个 Vuex 实例
const store = createStore({
    modules: {
        user
    },
    state: {
        // 菜单和路由是否已经加载
        routeLoaded: false,
        // 第一个路由，用于用户进入主页时的 redirect
        firstRoute: null,
        // 菜单树
        menuTree: null
    },
    mutations: {
        increment(state) {
            state.count++;
        },
        setRouteLoaded(state, loaded) {
            // 改变菜单和路由的加载状态
            state.routeLoaded = loaded;
        },
        setFirstRoute(state, route) {
            state.firstRoute = route;
        },
        setMenuTree(state, data) {
            state.menuTree = data;
        }
    }
});

// 导出 Vuex 实例
export default store;